%% Create new schedule for Behavior RIG 1

% File Name | warning: file will be overwritten without prompting
sch = 'SpecNotch_schedule_TEST.mat';
FN = ['C:\Behavior\Human Spectral-Notch Detection\Schedule Files\' sch];

clear schedule trialdef

%% parameter tags

% for RPvds direct access
schedule.writeparams = {'trial_type','StimBuffer~1','StimBufSize~1', ...
                                     'StimBuffer~2','StimBufSize~2','Stim2Delay'};
schedule.writemodule = [1 2 2 2 2 2];
schedule.readparams  = {'response_code'};
schedule.readmodule  = ones(size(schedule.readparams));
schedule.nreps       = 10;
schedule.randomize   = true;
schedule.schedule    = sch;

% for OpenEx
% schedule.writeparams = {'Stim.stim_duration','Stim.fm_sweep_delay', ...
%     'Stim.NoiseLP','Stim.NoiseHP','Stim.stim_delay','Stim.trial_type'};
% schedule.readparams  = {'Stim.trial_index'};
% schedule.OpExparams  = {'Stim.zSweep .....

%% Check yo' self
if length(schedule.writeparams) ~= length(schedule.writemodule)
	error('write params/module lengths differ!');
end

if length(schedule.readparams) ~= length(schedule.readmodule)
	error('read params/module lengths differ!');
end

%% trial defs
clear trialdef

% {1} stimulus duration;  {2} trial type: 0 = normal, 1 = catch

% 0 is normal trial;  1 is catch trial
trialdef{1} = {'buddy','Condition',[1000]};
trialdef{2} = {'buddy','Condition',[0]};

st = 0:10:70;

st1 = 10 .^ ((st - ones(size(st)) * 95.29) ./ 20);
st2 = 10 .^ ((st - ones(size(st)) * 96.10) ./ 20);
% st1 = 10 .^ ((st - ones(size(st)) * 97.89) ./ 20);
% st2 = 10 .^ ((st - ones(size(st)) * 93.26) ./ 20);

% noise amplitude
% trialdef{6} = {'buddy','Noise',[0.054387613, 0.017198873, 0.005438761, 0.001719887, 0.000543876, 0.000171989]};
% trialdef{7} = {'buddy','Noise',[0.049545019, 0.015667511, 0.004954502, 0.001566751, 0.00049545,  0.000156675]};
trialdef{6} = {'buddy','Noise',st1};
trialdef{7} = {'buddy','Noise',st2};
trialdef{8} = {'buddy','Noise',st};



% noise amplitude 
trialdef{6} = {'buddy','Noise',[1]};
    
trialdef{9} = {'randomized','round',[2000 5000]};

%% Get Unique Trials
schedule = BHVR_AddTrial(schedule,trialdef);

%% Save

save(FN,'schedule');

